package impl;

import anaydis.sort.SorterType;
import com.sun.istack.internal.NotNull;

import java.util.Comparator;
import java.util.List;


public class HSorter extends AbstractSorter{
    public HSorter() {
           super(SorterType.H);
    }

    public HSorter(SorterType shell) {
           super(shell);
    }

    public <T> void sort(@NotNull Comparator<T> tComparator, @NotNull List<T> ts) {
        int h=(int)ts.size()/2;
        //do{
        for(int i=0;i<h;i++){
            for(int j=i;j<ts.size();j=j+h){
                if(j+h<ts.size() && greater(tComparator,ts, j, j+h) ){
                    swap(ts,j,j+h);
                }
            }
        }
        //    h=h/2;
        //}while(h/2>=1);
    }

    public <T> void sort(@NotNull Comparator<T> tComparator, @NotNull List<T> ts, int w) {
        int r=w;
        for(int i=r-1;i<ts.size();i++){
            for(int j=i;(j>=r) && greater(tComparator,ts,j-r,j);j=j-r){
                swap(ts,j,j-r);
            }
        }
    }
}